fix clazy detected 'allocating an unneeded temporary container'
authortsteven4 <tsteven4@gmail.com>
Tue, 13 Nov 2018 14:59:10 +0000 (07:59 -0700)
committertsteven4 <tsteven4@gmail.com>
Tue, 13 Nov 2018 14:59:10 +0000 (07:59 -0700)
these are from -Wclazy-container-anti-pattern

Also, consistently use range based for loops in csv_util.cc

csv_util.cc
mmo.cc

index 034e34a34b2a3f460e31c72a87687c728aeb08c6..fb7d1f403f186db9f017d1247b88b161a35bec0b 100644 (file)
@@ -24,7 +24,7 @@
 #include <QtCore/QDateTime>        // for QDateTime, QDate
 #include <QtCore/QString>          // for QString, QCharRef
 #include <QtCore/QTextStream>      // for QTextStream
-#include <QtCore/QtGlobal>         // for foreach
+#include <QtCore/QtGlobal>         // for qAsConst
 
 #include "csv_util.h"
 #include "defs.h"
@@ -1421,7 +1421,7 @@ xcsv_data_read(void)
      * pre-read the file to know how many data lines we should be seeing,
      * we take this cheap shot at the data and cross our fingers.
      */
-    foreach(const QString& ogp, xcsv_file.epilogue) {
+    for(const auto& ogp : qAsConst(xcsv_file.epilogue)) {
        if (ogp.startsWith(buff)) {
          buff.clear();
          break;
diff --git a/mmo.cc b/mmo.cc
index 2c55cd63d88ef7c5e96f0911a2f4618005311c19..f211e8cf9bc2b61dff8b5955cb9d48836d198bc1 100644 (file)
--- a/mmo.cc
+++ b/mmo.cc
@@ -22,6 +22,7 @@
 
 #include "defs.h"
 #include <QtCore/QHash>
+#include <QtCore/QtGlobal>
 #include <cerrno>
 #include <cstdio>
 #include <cstdlib>
@@ -259,9 +260,9 @@ mmo_register_object(const int objid, const void* ptr, const gpsdata_type type)
 static int
 mmo_get_objid(const void* ptr)
 {
-  foreach(int key, objects.keys()) {
-    if (objects.value(key)->data == ptr) {
-      return key;
+  for (auto o = objects.constBegin(); o != objects.constEnd(); ++o) {
+    if (o.value()->data == ptr) {
+      return o.key();
     }
   }
   return 0;
@@ -305,7 +306,7 @@ mmo_free_object(mmo_data_t* data)
     xfree(data->name);
   }
   if ((data->type == wptdata) && (data->refct == 0)) {
-    delete(Waypoint*)data->data;
+    delete (Waypoint*)data->data;
   }
   xfree(data);
 }
@@ -973,8 +974,8 @@ mmo_rd_deinit()
 
   icons.clear();
 
-  foreach(int k, objects.keys()) {
-    mmo_free_object(objects.value(k));
+  for (auto value : qAsConst(objects)) {
+    mmo_free_object(value);
   }
   objects.clear();
 
@@ -1279,7 +1280,7 @@ mmo_write_rte_head_cb(const route_head* rte)
   mmo_rte = rte;
 
   QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+    Waypoint* wpt = reinterpret_cast<Waypoint*>(elem);
     QDateTime t = wpt->GetCreationTime();
     if ((t.isValid()) && (t.toTime_t() < time)) {
       time = t.toTime_t();
@@ -1323,7 +1324,7 @@ mmo_write_rte_tail_cb(const route_head* rte)
   }
 
   QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+    Waypoint* wpt = reinterpret_cast<Waypoint*>(elem);
     int objid = mmo_get_objid(wpt);
     gbfputuint16(objid & 0x7FFF, fout);
   }
@@ -1409,8 +1410,8 @@ mmo_wr_deinit()
   mmobjects.clear();
   category_names.clear();
 
-  foreach(int k, objects.keys()) {
-    mmo_free_object(objects.value(k));
+  for (auto value : qAsConst(objects)) {
+    mmo_free_object(value);
   }
   objects.clear();